import pluginVue from 'eslint-plugin-vue'
import pluginEslint from '@eslint/js'
import tseslint from 'typescript-eslint'

export default [
  // 基础ESLint推荐规则
  pluginEslint.configs.recommended,

  // TypeScript ESLint推荐规则
  ...tseslint.configs.recommended,

  // Vue ESLint推荐规则
  ...pluginVue.configs['flat/essential'],
  {
    env: {
      browser: true,
      node: true,
    },
  },
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
    ignores: ['**/dist/**', '**/node_modules/**'],
    languageOptions: {
      parserOptions: {
        parser: '@typescript-eslint/parser',
        ecmaVersion: 2020,
        sourceType: 'module'
      }
    },
    plugins: {
      '@typescript-eslint': tseslint.plugin
    },
    rules: {
      // TypeScript规则
      '@typescript-eslint/no-unused-vars': 'error',
      '@typescript-eslint/no-explicit-any': 'warn',

      // JavaScript规则
      'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',

      // 通用规则
      'indent': ['error', 2],
      'quotes': ['error', 'single'],
      'semi': ['error', 'never']
    }
  },

  {
    name: 'app/vue-files',
    files: ['**/*.vue'],
    languageOptions: {
      parserOptions: {
        parser: '@typescript-eslint/parser'
      }
    },
    plugins: {
      vue: pluginVue
    },
    rules: {
      'vue/multi-word-component-names': 'off',
      'vue/html-self-closing': 'off'
    }
  },

  // 忽略测试文件
  {
    name: 'app/test-files',
    files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
    rules: {
      'no-console': 'off'
    }
  }
]